<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
	<!--<![endif]-->
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>修改密码</title>
		<meta name="description" content="">
		<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
		<meta content="telephone=no" name="format-detection" />
		<meta content="black" name="apple-mobile-web-app-status-bar-style" />
		<!-- 引入样式 -->
		<link rel="stylesheet" href="styles/vant.css">
		<link rel="stylesheet" href="styles/common.css" />
		<link rel="stylesheet" href="styles/global.css" />
		<link rel="stylesheet" href="styles/login.css" />
		<link rel="stylesheet" href="styles/font.css">
		<!-- 引入组件 -->
		<script src="scripts/babel.js" type="text/javascript" charset="utf-8"></script>
		<script src="scripts/rem.js"></script>
		<script src="scripts/vue.js" type="text/javascript" charset="utf-8"></script>
		<script src="scripts/vant.js"></script>
		<script src="scripts/api.js" type="text/javascript" charset="utf-8"></script>
		<script src="scripts/axios.js" charset="utf-8"></script>
		<!-- <script src="//cdn.jsdelivr.net/npm/eruda"></script>
		<script>eruda.init();</script> -->
	</head>
	<body>
		<!--[if lt IE 7]>
            <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->

		<div class="container" id="app">
			<div class="header">
				<div @click="go_back"><i class="iconfont icon-back"></i></div>
				<div>修改密码</div>
				<div class="headericon"></div>
			</div>
			<div class="form">
				<div class="iteminput"><input type="password" placeholder="请输入原密码" name="" v-model="data_info.oldpsd"></div>				
				<div class="iteminput"><input type="password" placeholder="请输入新密码" name=""  v-model="data_info.password"></div>
				<div class="iteminput"><input type="password" placeholder="再次输入密码" name=""  v-model="data_info.sure_password"></div>
				<div style="padding-top:1rem;">
					<button :disabled="dis" @click="sure_forget" v-text="login_text" class="button"></button>
				</div>
			</div>
		</div>
	</body>
</html>
	<script type="text/babel">		
		new Vue({
			el: '#app',
			data: {
				url: "",
				userId: "",
				token: "",
				admin:"",
				tips: "发送验证码",
				timer: null,
				login_text:'确定',
				dis:false,
				data_info:{
					mid:"",
					password:"",
					sure_password:""
				}
			},			
			mounted: function() {
				this.url = url();
				console.log(localStorage.getItem("admin"))
				this.admin = JSON.parse(localStorage.getItem("admin"));
				this.userId = this.admin.mid;
				this.token = this.admin.token;
				this.data_info.mid = this.admin.mid
			},			
			methods: {
				sure_forget:function(){
					var that = this;
					if(that.data_info.oldpsd==''){
						that.$notify("请输入原密码");
						return false;
					}	
					if(that.data_info.password==''){
						that.$notify("请输入新密码");
						return false;
					}
					if(that.data_info.password.length<6){
						that.$notify("密码最少为六位");
						return false;
					}
					if(that.data_info.sure_password==''){
						that.$notify("请再次输入新密码");
						return false;
					}
					if(that.data_info.sure_password.length<6){
						that.$notify("密码最少为六位");
						return false;
					}
					if(that.data_info.sure_password!=that.data_info.password){
						that.$notify("二次输入的密码不一致");
						return false;
					}					
					console.log(that.data_info)
					var data = {
						userId: that.userId,
						token: that.token,
						requestString: JSON.stringify(that.data_info)
					};					
					that.login_text ="loading";
					that.dis = true;
					axios.post(that.url + '/mchapp/info/updatePassword', data)										
						.then(function(response) {								
							console.log(response);							
							if (response.data.code == 200) {
								that.$notify("修改成功，将为您跳转至登录页面");
								localStorage.removeItem('admin');
								setTimeout(function(){window.location.href = 'login.html';},2000);
							} //判断单点登录
							else if(response.data.code == 300){
								that.$notify("账号在别处登录，将为您返回登录页面");//							
								if(that.admin.teltype==1){
									logout_app(that.admin.mid,1)
								}
								if(that.admin.teltype==2){
									logout_app(that.admin.mid,2)
								}	
								window.location.href ='login.html';
							} else {
								that.login_text ="确定";
								that.dis = false;
								that.$notify(response.data.disp);
							}
						})
				},
				// 发送验证码
				send_code:function(){
					var that = this;
					if (that.tips != "发送验证码") {
						return
					}
					if (that.data_info.tel == '') {
						that.$notify("请输入手机号码");
						return false;
					};
					if (!(/^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/i.test(that.data_info.tel))) {
						that.$notify("手机格式不正确");
						return false;
					};
					var data = {
						tel: that.data_info.tel,
					}
					console.log(data)
					axios.post(that.url + '/no/mchappinfo/sendTelCodeForPsd', data).then(function(response) {							
							if (response.data.code == 200) {
								that.$notify('发送成功');
								that.tips_timer()
							}//判断单点登录
							else if(response.data.code == 300){
								that.$notify("账号在别处登录，将为您返回登录页面");//							
								if(that.admin.teltype==1){
									logout_app(that.admin.mid,1)
								}
								if(that.admin.teltype==2){
									logout_app(that.admin.mid,2)
								}							
							}  else {
								that.$notify(response.data.disp);
							}
						})
				},	
				tips_timer() {
					var TIME_COUNT = 60;
					var that = this;
					if (!this.timer) {
						this.count = TIME_COUNT;						
						this.timer = setInterval(() => {
							if (this.count > 0 && this.count <= TIME_COUNT) {
								this.count--;
								that.tips = this.count + "秒后在发送"
							} else {								
								clearInterval(this.timer);
								that.tips = "发送验证码"
								this.timer = null;
							}
						}, 1000)
					}
				},
				go_back: function() {
					window.history.back(-1);
				},
				go_login:function(){
					window.location.href = 'login.html';
				}	
			},

		})
	</script>
